const {verifyName} = require("../register/register.service")
const {md5Encry,send} = require("@common/utils")

const handleParams = async (ctx,next) => {
  try {
    const {name,password} = ctx.request.body
    let user = await verifyName(name)
    if(Object.keys(user)?.length === 0 ){
      return send(ctx,200,'-1','用户不存在')
    }
    // 验证密码
    if(md5Encry(password) !== user.password){
      return send(ctx,200,'-1','密码不正确')
    }

    ctx.user = user
    await next()
  } catch (error) {
    console.log(error);
  }
}

module.exports = {handleParams}